﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.DemandPlan
{
    public partial class DemandPlanCheckInvoiceType : System.Web.UI.Page
    {
        Maticsoft.BLL.workFlow wm = new Maticsoft.BLL.workFlow();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }


        private void Bind()
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                int dpid = Convert.ToInt32(Request["id"]);

                DataSet ds = wm.GetWorkFlowInfo(" document_id = " + dpid);

                this.GridView1.DataSource = ds;
                this.GridView1.DataBind();
            }
        }

        //审核通过
        protected void btn_yes_Click(object sender, EventArgs e)
        {
            if (!this.cbo_ptfp.Checked && !this.cbo_zzsptfp.Checked && !this.cbo_zzszyfp.Checked)
            {
                Maticsoft.Common.MessageBox.Show(this, "请选择需开具发票类型！");
                return;
            }

            #region 审核
            //if (!string.IsNullOrEmpty(Request["id"]))
            //{
            //    int dpid = Convert.ToInt32(Request["id"]);

            //    #region 更新发票类型操作
            //    lcs.BLL.demandplaninfo dm = new BLL.demandplaninfo();

            //    lcs.Model.demandplaninfo d_model = dm.GetModel(dpid);

            //    if (this.cbo_ptfp.Checked)
            //    {
            //        d_model.invoicetype = "普通发票";
            //    }
            //    if (this.cbo_zzsptfp.Checked)
            //    {
            //        d_model.invoicetype = "增值税普通发票";
            //    }
            //    if (this.cbo_zzszyfp.Checked)
            //    {
            //        d_model.invoicetype = "增值税专用发票";
            //    }

            //    bool t = dm.Update(d_model);
            //    #endregion

            //    List<Maticsoft.Model.documentFlowInfo> li = new Maticsoft.BLL.documentFlowInfo().GetModelList(" document_id = " + dpid);

            //    if (li.Count == 1)
            //    {
            //        Maticsoft.Model.documentFlowInfo d = li[0];

            //        string reason = this.txt_reason.Text;

            //        if (string.IsNullOrEmpty(reason))
            //        {
            //            reason = "同意";
            //        }

            //        int person_id = 0;
            //        if (Session["login"] != null)
            //        {
            //            DataSet ds = Session["login"] as DataSet;

            //            person_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);
            //        }

            //        //获取当前审批人审批节点号，transfer的undefine4记录的是该由哪个审批人审批的节点号，如果要修改自身的workFlow，则节点号就是undefine4
            //        int flow_node_num_now = Convert.ToInt32(d.flow_node_num_now);
            //        int flow_node_id_now = 0;

            //        flow_node_id_now = wm.GetFlow_node_id_now(person_id, d.document_id.Value, flow_node_num_now);

            //        if (wm.UpdateW(person_id, d.document_id.Value, 1, reason, DateTime.Now, flow_node_id_now, flow_node_num_now))//修改本身意见为同意,添加处理意见、处理时间
            //        {
            //            int flow_node_id = wm.GetFlow_node_id(person_id, d.document_id.Value, Convert.ToInt32(d.flow_node_num_now));

            //            string str = wm.Submit_judge(flow_node_id, person_id, d.document_id.Value, Convert.ToInt32(d.flow_node_num_now));//得到审核状态

            //            if (str == "同意")//1、如果是会签非尾节点同意，插入下一节点
            //            {
            //                lcs.BLL.Tools.DealWorkFlow(d, flow_node_id, person_id);

            //            }

            //            if (str == "尾节点同意")//2、如果是会签尾节点同意
            //            {
            //                lcs.BLL.Tools.DealLast(d, person_id);

            //            }

            //            if (str == "非会签")//3、如果是非会签非尾节点，插入下一结点
            //            {
            //                lcs.BLL.Tools.DealWorkFlow(d, flow_node_id, person_id);
            //            }

            //            if (str == "尾节点非会签")
            //            {
            //                lcs.BLL.Tools.DealLast(d, person_id);
            //            }
            //        }

            //        Response.Redirect("ListDemandPlan.aspx");
            //    }

            //}
            #endregion


            if (!string.IsNullOrEmpty(Request["id"]))
            {
                int dpid = Convert.ToInt32(Request["id"]);

                #region 更新发票类型操作
                lcs.BLL.demandplaninfo dm = new BLL.demandplaninfo();

                lcs.Model.demandplaninfo d_model = dm.GetModel(dpid);

                if (this.cbo_ptfp.Checked)
                {
                    d_model.invoicetype = "普通发票";
                }
                if (this.cbo_zzsptfp.Checked)
                {
                    d_model.invoicetype = "增值税普通发票";
                }
                if (this.cbo_zzszyfp.Checked)
                {
                    d_model.invoicetype = "增值税专用发票";
                }

                bool t = dm.Update(d_model);
                #endregion

                string reason = this.txt_reason.Text;

                if (string.IsNullOrEmpty(reason))
                {
                    reason = "同意";
                }


                int person_id = 0;
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    person_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);
                }

                //同意处理
                lcs.BLL.Tools.DealAgree(dpid, person_id, reason);

                Response.Redirect("ListDemandPlan.aspx");
            }
        }

        //审核未通过
        protected void btn_no_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                int dpid = Convert.ToInt32(Request["id"]);

                string reason = this.txt_reason.Text;

                if (string.IsNullOrEmpty(reason))
                {
                    reason = "否决";
                }


                int person_id = 0;
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    person_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);
                }

                //返回上一步
                lcs.BLL.Tools.DealDisagreeLast(dpid, person_id, reason);

                Response.Redirect("ListDemandPlan.aspx");
            }

        }

       

    }
}